import 'package:flutter/material.dart';
import 'package:pp_uikit/theme/pp_default_theme.dart';

/// ActionSheet 主题配置
class PPActionSheetTheme {
  /// 遵循外部主题配置
  PPActionSheetTheme({
    TextStyle? titleStyle,
    TextStyle? itemTitleStyle,
    TextStyle? itemTitleStyleLink,
    TextStyle? itemTitleStyleAlert,
    TextStyle? itemDescStyle,
    TextStyle? itemDescStyleLink,
    TextStyle? itemDescStyleAlert,
    TextStyle? cancelStyle,
    Size? imageSize,
    double? topRadius,
    EdgeInsets? contentPadding,
    EdgeInsets? titlePadding,
  })  : _titleStyle = titleStyle,
        _itemTitleStyle = itemTitleStyle,
        _itemTitleStyleLink = itemTitleStyleLink,
        _itemTitleStyleAlert = itemTitleStyleAlert,
        _itemDescStyle = itemDescStyle,
        _itemDescStyleLink = itemDescStyleLink,
        _itemDescStyleAlert = itemDescStyleAlert,
        _cancelStyle = cancelStyle,
        _topRadius = topRadius,
        _contentPadding = contentPadding,
        _titlePadding = titlePadding,
        _imageSize = imageSize,
        super();

  /// 图片大小，默认18
  final Size? _imageSize;

  /// ActionSheet 的顶部圆角

  final double? _topRadius;

  /// 标题样式
  ///
  /// TextStyle(
  /// )
  final TextStyle? _titleStyle;

  /// 元素标题默认样式
  ///
  /// TextStyle(
  /// )
  final TextStyle? _itemTitleStyle;

  /// 元素标题链接样式
  ///
  /// TextStyle(
  ///   fontWeight: FontWeight.w600,
  /// )
  final TextStyle? _itemTitleStyleLink;

  /// 元素警示项标题样式
  ///
  /// TextStyle(
  ///   fontWeight: FontWeight.w600,
  /// )
  final TextStyle? _itemTitleStyleAlert;

  /// 元素描述默认样式
  ///
  /// TextStyle(
  ///   fontWeight: FontWeight.w600,
  /// )
  final TextStyle? _itemDescStyle;

  /// 元素标题描述链接样式
  ///
  /// TextStyle(

  ///   fontWeight: FontWeight.w600,
  /// )
  final TextStyle? _itemDescStyleLink;

  /// 元素警示项标题描述样式
  ///
  /// TextStyle(

  ///   fontWeight: FontWeight.w600,
  /// )
  final TextStyle? _itemDescStyleAlert;

  /// 取消按钮样式
  ///
  /// TextStyle(

  ///   fontWeight: FontWeight.w600,
  /// )
  final TextStyle? _cancelStyle;

  /// 内容左右间距
  ///
  /// EdgeInsets.symmetric(horizontal: 60, vertical: 12)
  final EdgeInsets? _contentPadding;

  /// 标题左右间距
  ///
  /// EdgeInsets.symmetric(horizontal: 60, vertical: 16)
  final EdgeInsets? _titlePadding;

  Size get imageSize => _imageSize ?? const Size(18, 18);
  double get topRadius =>
      _topRadius ?? PPDefaultTheme.defaultActionSheetConfig.topRadius;

  TextStyle get titleStyle =>
      _titleStyle ?? PPDefaultTheme.defaultActionSheetConfig.titleStyle;

  TextStyle get itemTitleStyle =>
      _itemTitleStyle ?? PPDefaultTheme.defaultActionSheetConfig.itemTitleStyle;

  TextStyle get itemTitleStyleLink =>
      _itemTitleStyleLink ??
      PPDefaultTheme.defaultActionSheetConfig.itemTitleStyleLink;

  TextStyle get itemTitleStyleAlert =>
      _itemTitleStyleAlert ??
      PPDefaultTheme.defaultActionSheetConfig.itemTitleStyleAlert;

  TextStyle get itemDescStyle =>
      _itemDescStyle ?? PPDefaultTheme.defaultActionSheetConfig.itemDescStyle;

  TextStyle get itemDescStyleLink =>
      _itemDescStyleLink ??
      PPDefaultTheme.defaultActionSheetConfig.itemDescStyleLink;

  TextStyle get itemDescStyleAlert =>
      _itemDescStyleAlert ??
      PPDefaultTheme.defaultActionSheetConfig.itemDescStyleAlert;

  TextStyle get cancelStyle =>
      _cancelStyle ?? PPDefaultTheme.defaultActionSheetConfig.cancelStyle;

  EdgeInsets get contentPadding =>
      _contentPadding ?? PPDefaultTheme.defaultActionSheetConfig.contentPadding;

  EdgeInsets get titlePadding =>
      _titlePadding ?? PPDefaultTheme.defaultActionSheetConfig.titlePadding;

  PPActionSheetTheme copyWith({
    double? topRadius,
    TextStyle? titleStyle,
    TextStyle? itemTitleStyle,
    TextStyle? itemTitleStyleLink,
    TextStyle? itemTitleStyleAlert,
    TextStyle? itemDescStyle,
    TextStyle? itemDescStyleLink,
    TextStyle? itemDescStyleAlert,
    TextStyle? cancelStyle,
    EdgeInsets? contentPadding,
    EdgeInsets? titlePadding,
  }) {
    return PPActionSheetTheme(
      titleStyle: titleStyle ?? _titleStyle,
      itemTitleStyle: itemTitleStyle ?? _itemTitleStyle,
      itemTitleStyleLink: itemTitleStyleLink ?? _itemTitleStyleLink,
      itemTitleStyleAlert: itemTitleStyleAlert ?? _itemTitleStyleAlert,
      itemDescStyle: itemDescStyle ?? _itemDescStyle,
      itemDescStyleLink: itemDescStyleLink ?? _itemDescStyleLink,
      itemDescStyleAlert: itemDescStyleAlert ?? _itemDescStyleAlert,
      cancelStyle: cancelStyle ?? _cancelStyle,
      topRadius: topRadius ?? _topRadius,
      contentPadding: contentPadding ?? _contentPadding,
      titlePadding: titlePadding ?? _titlePadding,
    );
  }

  PPActionSheetTheme merge(PPActionSheetTheme? other) {
    if (other == null) return this;
    return copyWith(
      titleStyle: titleStyle.merge(other._titleStyle),
      itemTitleStyle: itemTitleStyle.merge(other._itemTitleStyle),
      itemTitleStyleLink: itemTitleStyleLink.merge(other._itemTitleStyleLink),
      itemTitleStyleAlert:
          itemTitleStyleAlert.merge(other._itemTitleStyleAlert),
      itemDescStyle: itemDescStyle.merge(other._itemDescStyle),
      itemDescStyleLink: itemDescStyleLink.merge(other._itemDescStyleLink),
      itemDescStyleAlert: itemDescStyleAlert.merge(other._itemDescStyleAlert),
      cancelStyle: cancelStyle.merge(other._cancelStyle),
      topRadius: other._topRadius,
      contentPadding: other._contentPadding,
      titlePadding: other._titlePadding,
    );
  }
}
